package leetcode20211009;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LUYAO
 * Date: 2021-10-09
 * Time: 17:36
 */
public class Array {
}

//调整数组使得奇数位于偶数前面
class Solution1 {
    public int[] exchange(int[] nums) {
        int a = 0;
        int b = nums.length-1;
        int tmp = 0;
        while(a < b) {
            while (a < b && nums[a] % 2 == 1) a++;
            while (a < b && nums[b] % 2 == 0) b--;
            tmp = nums[a];
            nums[a] = nums[b];
            nums[b] = tmp;
        }
        return nums;

    }
}

//输出给定数字的和的形式
class Solution2 {
    public int[] twoSum(int[] nums, int target) {
        int i = 0, j = nums.length - 1;
        while(i < j) {
            int s = nums[i] + nums[j];
            if(s < target) i++;
            else if(s > target) j--;
            else return new int[] { nums[i], nums[j] };
        }
        return new int[0];
    }
}
